<?php
/**
 * Unfuddle Changeset Model
 * Repository changesets
 *
 * @package     Unfuddle
 * @subpackage  Data Models
 * @author      Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright   (c) 2010 Luke Visinoni <luke.visinoni@gmail.com>
 * @version     $Id: Changeset.php 29 2011-05-09 07:08:53Z luke.visinoni $
 */
class Unfuddle_Model_Changeset extends Unfuddle_Model_Abstract {

    /**
     * All changesets within a repository
     */
    const URI_CHANGESETS = '/repositories/%d/changesets';
    
    /**
     * Returns a changeset by repository id and changeset id
     */
    const URI_CHANGESET_BY_ID = '/repositories/%d/changesets/%d';
    
    /**
     * Review/Commit a revision
     */
    const URI_CHANGESET_COMMIT = '/repositories/%d/commit/%d';
    
    /**
     * Latest changeset
     */
    const URI_CHANGESET_LATEST = '/repositories/%d/changesets/latest';
    
    /**
     * Unfuddle is capable of processing the commit message for any Changeset
     * and using it to modify the status of tickets (i.e. "Closed #432"). Performing
     * an HTML PUT to this resource will process any actions that are present in the commit message.
     */
    const URI_PROCESS_MESSAGE_ACTIONS = '/repositories/%d/changesets/%d/process_message_actions';
    
    /**
     * Returns a representation of a Commit in a Repository. This includes
     * commit information, file diffs and comments on the commit.
     */
    const URI_COMMIT = '/repositories/%d/commit';
    
    /**
     * Returns a Unidiff file to reflect changes in the specified commit.
     */
    const URI_DIFF = '/repositories/%d/diff';
    
    /**
     * Returns the requested file at the specified revision
     */
    const URI_DOWNLOAD = '/repositories/%d/download';
    
    /**
     * Returns a repository dump at the specified revision.
     */
    const URI_DOWNLOAD_REVISION = '/repositories/%d/download_revision';
    
    /**
     * Returns a representation of the requested file.
     */
    const URI_FILE = '/repositories/%d/file';
    
    /**
     * Returns the history of a specific file.
     */
    const URI_HISTORY = '/repositories/%d/history';
    
    /**
     * Returns a representation of the requested directory.
     */
    const URI_TREE = '/repositories/%d/tree';
    
    /**
     * Get changesets associated with a certain ticket
     */
    const URI_ASSOCIATED_CHANGESETS_BY_TICKET_ID = '/projects/{project_id}/tickets/{ticket_id}/associated_changesets';
    
    /**
     * DEPRECATED! Process message actions
     */
    const URI_PROJECT_PROCESS_MESSAGE_ACTIONS = '/projects/%d/changesets/%d/process_message_actions';
    
    /**
     * DEPRECATED! All changesets within a repository
     */
    const URI_PROJECT_CHANGESETS = '/projects/%d/changesets';
    
    /**
     * DEPRECATED! All changesets within a repository
     */
    const URI_PROJECT_CHANGESET_BY_ID = '/projects/%d/changesets/%d';
    
    /**
     * DEPRECATED! Latest changeset
     */
    const URI_PROJECT_CHANGESET_LATEST = '/projects/%d/changesets/latest';
    
    /**
     * @var string Model name
     */
    protected $_name = 'changeset';
    
    /**
     * @var array Model fields
     */
    protected $_fields = array (
        /**
         * Note that not all repositories systems distinguish between
         * the author and committer (i.e. Subversion does not)
         */
        'author-id' => array('type' => 'integer', 'required' => false, 'read-only' => false),
        'author-name' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'author-email' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'author-date' => array('type' => 'datetime', 'required' => false, 'read-only' => false), // the date the patch was authored
        'committer-id' => array('type' => 'integer', 'required' => false, 'read-only' => false),
        'committer-name' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'committer-email' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'committer-date' => array('type' => 'datetime', 'required' => false, 'read-only' => false), // the date the patch was committed
        'created-at' => array('type' => 'datetime', 'required' => false, 'read-only' => false),
        'id' => array('type' => 'integer', 'required' => false, 'read-only' => true),
        'message' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'message-formatted' => array('type' => 'text', 'required' => false, 'read-only' => true), // only available if formatted=true
        'repository-id' => array('type' => 'integer', 'required' => false, 'read-only' => true),
        'revision' => array('type' => 'text', 'required' => false, 'read-only' => false),
    );

}
